//
//  PushNative.m
//  MyApp
//
//  Created by 华生升 on 2018/4/12.
//  Copyright © 2018年 Facebook. All rights reserved.
//

#import "PushNative.h"
#import "AddressViewController.h"

// 导入AppDelegate，获取UINavigationController
#import "AppDelegate.h"



@implementation PushNative



RCT_EXPORT_MODULE();
// RN跳转原生界面
// RNOpenOneVC指的就是跳转的方法，下面会用到
RCT_EXPORT_METHOD(RNOpenOneVC:(NSString *)msg){
  
  NSLog(@"RN传入原生界面的数据为:%@",msg);
  
    // 在这里执行长时间的操作
    //主要这里必须使用主线程发送,不然有可能失效
    dispatch_async(dispatch_get_main_queue(), ^{
      AddressViewController *one = [[AddressViewController alloc]init];
      
      AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
      
      
      [app.rootViewController presentViewController:one animated:YES completion:nil];
      
    });

}
- (NSArray<NSString *> *)supportedEvents {
  return @[@"AddressNot"]; //这里返回的将是你要发送的消息名的数组。
}
- (void)startObserving
{
  [[NSNotificationCenter defaultCenter] addObserver:self
                                           selector:@selector(emitEventInternal:)
                                               name:@"event-emitted"
                                             object:nil];
}
- (void)stopObserving
{
  [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)emitEventInternal:(NSNotification *)notification
{
  [self sendEventWithName:@"AddressNot"
                     body:notification.object];
}

+ (void)postNotiToReactNative:(NSDictionary *)args{
  [[NSNotificationCenter defaultCenter] postNotificationName:@"event-emitted" object:args];
}
@end
